package org.boyan.modules.cgform.util;

import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.SecureRandom;
import java.util.Base64;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.spec.SecretKeySpec;
import org.boyan.common.util.oConvertUtils;

public class k {
    public static String a(byte[] paramArrayOfbyte, int paramInt) {
        return (new BigInteger(1, paramArrayOfbyte)).toString(paramInt);
    }

    public static String a(byte[] paramArrayOfbyte) {
        return Base64.getEncoder().encodeToString(paramArrayOfbyte);
    }

    public static byte[] a(String paramString) throws Exception {
        return oConvertUtils.isEmpty(paramString) ? null : Base64.getDecoder().decode(paramString);
    }

    public static byte[] b(byte[] paramArrayOfbyte) throws Exception {
        MessageDigest messageDigest = MessageDigest.getInstance("MD5");
        messageDigest.update(paramArrayOfbyte);
        return messageDigest.digest();
    }

    public static byte[] b(String paramString) throws Exception {
        return oConvertUtils.isEmpty(paramString) ? null : b(paramString.getBytes());
    }

    public static String c(String paramString) throws Exception {
        return oConvertUtils.isEmpty(paramString) ? null : a(b(paramString));
    }

    public static byte[] a(String paramString1, String paramString2) throws Exception {
        KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
        keyGenerator.init(128, new SecureRandom(paramString2.getBytes()));
        Cipher cipher = Cipher.getInstance("AES");
        cipher.init(1, new SecretKeySpec(keyGenerator.generateKey().getEncoded(), "AES"));
        return cipher.doFinal(paramString1.getBytes(StandardCharsets.UTF_8));
    }

    public static String b(String paramString1, String paramString2) throws Exception {
        return a(a(paramString1, paramString2));
    }

    public static String a(byte[] paramArrayOfbyte, String paramString) throws Exception {
        KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
        keyGenerator.init(128, new SecureRandom(paramString.getBytes()));
        Cipher cipher = Cipher.getInstance("AES");
        cipher.init(2, new SecretKeySpec(keyGenerator.generateKey().getEncoded(), "AES"));
        byte[] arrayOfByte = cipher.doFinal(paramArrayOfbyte);
        return new String(arrayOfByte);
    }

    public static String c(String paramString1, String paramString2) throws Exception {
        return oConvertUtils.isEmpty(paramString1) ? null : a(a(paramString1), paramString2);
    }
}
